package com.dianplus.biz.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static com.dianplus.biz.config.Constants.SPRING_PROFILE_PRODUCTION;

@Slf4j
@Configuration
@EnableSwagger2
@Profile("!" +SPRING_PROFILE_PRODUCTION)
public class SwaggerConfiguration {
    //是否开启swagger，正式环境一般是需要关闭的，可根据springboot的多环境配置进行设置
    @Value(value = "${swagger.enabled:true}")
    Boolean swaggerEnabled;
    @Bean
    public Docket buildDocket() {
        log.debug("swagger buid Docket");
        return new Docket(DocumentationType.SWAGGER_2)
                // 是否开启
                .apiInfo(buildApiInf()) // .apiInfo(apiInfo())
                .enable(swaggerEnabled).select()
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo buildApiInf() {
        return new ApiInfoBuilder()
                .title("店佳业务系统接口详情")
                .description("Zuul+Swagger2构建RESTful APIs")
                .termsOfServiceUrl("http://www.dianjia001.com")
                .contact(new Contact("jn", "http://www.dianjia001.com", ""))
                .version("1.0")
                .build();
    }


}
